package com.google.gwt.xhr.client;

import com.google.gwt.core.client.EntryPoint;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class XMLHTTPTest implements EntryPoint {
  XMLHTTPRequest2 xhr;

  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {

    
    //Test xhr new events
    xhr = (XMLHTTPRequest2) XMLHTTPRequest2.create();
    final String url = "http://127.0.0.1:8888/xmlhttprequest2/request?test=hahaha";
    xhr.open("GET", url);
    // xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    AbstractProgressHandler h = new AbstractProgressHandler() {
      
      public void onProgress(XMLHttpRequest xhr) {
        System.out.println("on Progress");
      }
      
      public void onAbort(XMLHttpRequest xhr) {
        System.out.println("on Abort");
      }
      
      public void onError(XMLHttpRequest xhr) {
        System.out.println("on Error");
      }
      
      public void onLoad(XMLHttpRequest xhr) {
        System.out.println("on Load");
        System.out.println("  Response Text:" + xhr.getResponseText());        
      }
      
      public void onLoadEnd(XMLHttpRequest xhr) {
        System.out.println("on LoadEnd");
      }
      
      public void onLoadStart(XMLHttpRequest xhr) {
        System.out.println("on LoadStart");
        System.out.println("  request URL: " + url);
      }
      
      public void onTimeOut(XMLHttpRequest xhr) {
        System.out.println("on TimeOut");
      }
    };
    
    xhr.setTimeOut(50);
    
    xhr.setOnProgress(h);
    xhr.setOnAbort(h);
    xhr.setOnError(h);
    xhr.setOnLoad(h);
    xhr.setOnLoadEnd(h);
    xhr.setOnLoadStart(h);
    xhr.setOnTimeOut(h);
    xhr.send();
  }
}
